home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / AddCreds / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  6KB  |  243 lines

  1.  
  2. #include <exec/types.h>
  3. #include <exec/memory.h>
  4. #include <dos/dos.h>
  5. #include <clib/exec_protos.h>
  6. #include <clib/dos_protos.h>
  7. #include <clib/alib_protos.h>
  8.  
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <ctype.h>
  13. #include <time.h>
  14.  
  15.  
  16. #ifdef __SASC
  17. int CXBRK(void) { return(0); }
  18. int _CXBRK(void) { return(0); }
  19. void chkabort(void) {}
  20. #endif
  21.  
  22. #include <HBBS/ANSI_Codes.h>
  23. #include <HBBS/Defines.h>
  24. #include <HBBS/types.h>
  25. #include <HBBS/structures.h>
  26. #include <HBBS/hbbscommon_protos.h>
  27. #include <HBBS/hbbscommon_pragmas.h>
  28. #include <HBBS/Hbbsnode_protos.h>
  29. #include <HBBS/Hbbsnode_pragmas.h>
  30. #include <HBBS/release.h>
  31. char *versionstr="$VER: AddCreds "RELEASE_STR;
  32.  
  33. struct Library *HBBSCommonBase=NULL;
  34. struct Library *HBBSNodeBase=NULL;
  35.  
  36. struct BBSGlobalData *BBSGlobal=NULL;
  37. struct NodeData *N_ND=NULL;
  38. int N_NodeNum=-1;
  39. char outstr[1024]; // temp string for displaying text..
  40.  
  41. static VOID cleanup(ULONG num)
  42. {
  43.   if (HBBSNodeBase)
  44.   {
  45.     HBBS_CleanUpDoor();
  46.     CloseLibrary (HBBSNodeBase);
  47.   }
  48.  
  49.   if (HBBSCommonBase)
  50.   {
  51.     HBBS_CleanUpCommon();
  52.     CloseLibrary (HBBSCommonBase);
  53.   }
  54.  
  55.   if (num) printf("Door Error = %d\n",num);
  56.  
  57.   exit(0);
  58. }
  59.  
  60. static VOID init(char *name)
  61. {
  62.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  63.   {
  64.     cleanup(1);
  65.   }
  66.  
  67.   if (!(HBBS_InitCommon()))
  68.   {
  69.     cleanup(2);
  70.   }
  71.  
  72.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  73.   {
  74.     cleanup(3);
  75.   }
  76.  
  77.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  78.   {
  79.     cleanup(4);
  80.   }
  81.   SetProgramName(name);
  82. }
  83.  
  84. void AwardCredits(V_BIGNUM ConfNum,LONG Creds,char *FileName)
  85. {
  86.  
  87.   // *C* update for conference accounting..
  88.  
  89.   N_ND->User.CallData.UploadBytes+=Creds;
  90.   N_ND->User.NormalData.UploadBytes+=Creds;
  91.   N_ND->User.CallData.UploadFiles++;
  92.   N_ND->User.NormalData.UploadFiles++;
  93.  
  94. //*** Protocol door now handles these now...
  95. //
  96. //  N_ND->User.CallData.ActualUploadBytes+=Creds;
  97. //  N_ND->User.NormalData.ActualUploadBytes+=Creds;
  98. //  N_ND->User.CallData.ActualUploadFiles++;
  99. //  N_ND->User.NormalData.ActualUploadFiles++;
  100.  
  101. }
  102.  
  103. void DoorMain(int argc,char *argv[])
  104. {
  105.   struct CfgFileData *AutoAwardCFG=NULL;
  106.   struct List *AwardFile=NULL;
  107.   struct List *AwardOpts=NULL;
  108.   LONG AwardSize=0,p,Matched=0;
  109.   V_BOOL StopOnFirstMatch=TRUE;
  110.   BOOL ExaminedOK=FALSE,FoundMatch,Done=FALSE;
  111.   ULONG AwardFiles=0;
  112.   V_BIGNUM ConfNum;
  113.   struct Node *node,*node2;
  114.   char matchstr[256];
  115.   BPTR FL;
  116.   struct FileInfoBlock FB;
  117.  
  118.   ConfNum=atoi(argv[2]);
  119.  
  120.   if ((ConfNum<1) || (ConfNum>BBSGlobal->Conferences))
  121.   {
  122.     DOOR_WriteText("Invalid Conference!\r\n");
  123.   }
  124.   else
  125.   {
  126.     // get details about the file that was uploaded..
  127.  
  128.     strcpy(outstr,N_ND->NodeSettings.NodePlayPen);
  129.     strcat(outstr,argv[3]);
  130.     if (FL=Lock(outstr,ACCESS_READ))
  131.     {
  132.       if (Examine(FL,&FB))
  133.       {
  134.         ExaminedOK=TRUE;
  135.       }
  136.       UnLock(FL);
  137.     }
  138.     if (!ExaminedOK)
  139.     {
  140.       sprintf(outstr,"Error Awarding Credits\n"
  141.                      "User: %s\n"
  142.                      "File: %s\n"
  143.                      "Reason: Could Not find File!",N_ND->User.CallData.Handle,argv[3]);
  144.       HBBS_LogError(BBSGlobal->ErrorLogFile,ERR_GENERAL,outstr,TYPE_WARNING);
  145.       DOOR_WriteText("Could Not Find File!\r\n");
  146.     }
  147.     else
  148.     {
  149.       // get the filename of the config file (same dir as executable..)
  150.       strcpy(outstr,argv[0]);
  151.       if ((p=iposition(".HBBS",outstr))==(strlen(outstr)-5))
  152.       {
  153.         outstr[p]=0; //terminate string
  154.       }
  155.       strcat(outstr,".CFG");
  156.  
  157.  
  158.       if (AutoAwardCFG=HBBS_LoadConfig(outstr,LCFG_NONE))
  159.       {
  160.         HBBS_GetSetting(AutoAwardCFG,(void *)&StopOnFirstMatch,VTYPE_BOOL,"StopOnFirstMatch",OPT_SINGLE);
  161.         if (AwardFiles=HBBS_GetSetting(AutoAwardCFG,(void *)&AwardFile,VTYPE_STRINGLIST,"AwardFile",OPT_MULTI))
  162.         {
  163.           if (AwardFiles==HBBS_GetSetting(AutoAwardCFG,(void *)&AwardOpts,VTYPE_STRINGLIST,"AwardOpts",OPT_MULTI))
  164.           {
  165.             for (node = AwardFile->lh_Head , node2 = AwardOpts->lh_Head ; node->ln_Succ && node2->ln_Succ && !Done ; node =node->ln_Succ,node2 =node2->ln_Succ)
  166.             {
  167.               FoundMatch=FALSE;
  168.               ParsePatternNoCase(node->ln_Name,matchstr,255);
  169.               if (MatchPatternNoCase(matchstr,argv[3]))
  170.               {
  171.                 if (node2->ln_Name[0]) // a blank string ?
  172.                 {
  173.                   sscanf(&node2->ln_Name[1],"%ld",&AwardSize);
  174.                   if (AwardSize>0)
  175.                   {
  176.                     switch(node2->ln_Name[0])
  177.                     {
  178.                       case '+':
  179.                         FoundMatch=TRUE;
  180.                         AwardSize=FB.fib_Size+AwardSize;
  181.                         break;
  182.                       case '-':
  183.                         FoundMatch=TRUE;
  184.                         AwardSize=FB.fib_Size-AwardSize;
  185.                         break;
  186.                       case '*':
  187.                         FoundMatch=TRUE;
  188.                         AwardSize=FB.fib_Size*AwardSize;
  189.                         break;
  190.                       case '/':
  191.                         FoundMatch=TRUE;
  192.                         AwardSize=FB.fib_Size/AwardSize;
  193.                         break;
  194.                     }
  195.                     if (FoundMatch)
  196.                     {
  197.                       Matched++;
  198.                       sprintf(outstr,ANSI_RESET ANSI_FG_YELLOW "Awarding %ld%s=%ld credits for %s\r\n" ANSI_RESET,FB.fib_Size,node2->ln_Name,AwardSize,argv[3]);
  199.                       DOOR_WriteText(outstr);
  200.                       AwardCredits(ConfNum,AwardSize,argv[3]);
  201.                     }
  202.                   }
  203.                 }
  204.               }
  205.               if (StopOnFirstMatch && FoundMatch) Done=TRUE;
  206.             }
  207.             if (Matched==0)
  208.             {
  209.               sprintf(outstr,ANSI_RESET ANSI_FG_GREEN "Awarding %ld credits for %s\r\n" ANSI_RESET,FB.fib_Size,argv[3]);
  210.               DOOR_WriteText(outstr);
  211.               AwardCredits(ConfNum,FB.fib_Size,argv[3]);
  212.             }
  213.           }
  214.           else DOOR_WriteText("Config File Mismatch\r\n");
  215.         }
  216.       }
  217.       else
  218.       {
  219.         AwardCredits(ConfNum,FB.fib_Size,argv[2]);
  220.       }
  221.     }
  222.   }
  223. }
  224.  
  225. int main(int argc,char *argv[])
  226. {
  227.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  228.   {
  229.     printf("Invalid/No Paramaters for door!\n");
  230.     exit (20);
  231.   }
  232.   init("AddCreds");
  233.  
  234.   if (BBSGlobal=HBBS_GimmeBBS())
  235.   {
  236.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  237.     {
  238.       DoorMain(argc,argv);
  239.     }
  240.   }
  241.   cleanup(0);
  242. }
  243.